#include "rustcourse.h"
#include "qrcutil.h"

RustCourse::RustCourse() {}

QString RustCourse::name()
{
    return "Rust - 圣经";
}

QString RustCourse::prefix()
{
    return "https://course.rs/";
}

QList<QListWidgetItem*> RustCourse::searching_item(const QString &text)
{
    QList<QListWidgetItem*> list;
    foreach (auto line, QR("://rust-course.txt").split("\n", Qt::SkipEmptyParts)) {
        auto title = line.mid(line.indexOf(">")+1);
        title = title.mid(0, title.indexOf("<"));
        auto href = line.mid(line.indexOf("href=\"")+6);
        href = href.mid(0, href.indexOf("\">"));

        if (text.isEmpty() || title.contains(text, Qt::CaseInsensitive)) {
            auto item = newItem();
            item->setText(title);
            item->setData(990, href);
            list << item;
        }
    }
    return list;
}

QString RustCourse::content_item(const QListWidgetItem *item)
{
    return prefix() + item->data(990).toString();
}
